package wodegua.d4_atm;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Atm {
    private ArrayList<Account> list = new ArrayList<>();
    Scanner scanner = new Scanner(System.in);

    //添加账户
    public void addAccount(){
        System.out.println("请输入账号：");
        String name = scanner.next();
        System.out.println("请输入密码：");
        String password = scanner.next();
        System.out.println("请确认密码：");
        while (true) {
            String comPassword = scanner.next();
            if (!comPassword.equals(password)) {
                System.out.println("两次密码不一致，请重新输入：");
            } else {
                break;
            }
        }
        System.out.println("请输入限额：");
        double amountLimit = scanner.nextDouble();

        Random random = new Random();

        Account account = new Account(name, password, String.valueOf(random.nextInt(10) + 100), 0,amountLimit);
        list.add(account);
        System.out.println("开通账户成功：");
        System.out.println("账户："+account.getName());
        System.out.println("密码："+account.getPassword());
        System.out.println("金额："+account.getAmount());
        System.out.println("限额："+account.getAmountLimit());
    }

    public void start(){
        while (true) {
            System.out.println("请输入操作命令：");
            System.out.println("1:开户");
            System.out.println("2:查询");
            System.out.println("3:退出");
            int op = scanner.nextInt();
            switch (op) {
                case 1:
                    addAccount();
                    break;
                case 2:
                    for (int i = 0; i < list.size(); i++) {
                        System.out.println("姓名：" + list.get(i).getName());
                        System.out.println("余额：" + list.get(i).getAmount());
                        System.out.println("限额：" + list.get(i).getAmountLimit());
                        System.out.println("-----------------------------");
                    }
                    break;
                case 3:
                    System.out.println("谢谢使用");
                    break;
                default:
                    System.out.println("错误的操作命令");
            }
        }
    }
}
